package com.zimmur.app.mocolink.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zimmur.app.mocolink.dao.GoodsBrandMapper;
import com.zimmur.app.mocolink.domain.model.GoodsBrand;
import com.zimmur.app.mocolink.domain.param.GoodsBrandReqParam;
import com.zimmur.app.mocolink.domain.util.PageUtil;
import com.zimmur.app.mocolink.domain.vo.GoodsBrandInfo;
import com.zimmur.app.mocolink.service.IGoodsBrandService;

@Service
public class GoodsBrandServiceImpl implements IGoodsBrandService{

	@Autowired
	private GoodsBrandMapper goodsBrandMapper;

	@Override
	public List<GoodsBrandInfo> queryEntireBrand() {
		return goodsBrandMapper.queryEntireBrand();
	}

	@Override
	public PageUtil<GoodsBrand> queryBrandInfo(GoodsBrandReqParam brandParam) {
		PageUtil<GoodsBrand> page  = new PageUtil<>();
		List<GoodsBrand> list=goodsBrandMapper.selectByMuchParam(brandParam);
		int count = goodsBrandMapper.countByParam(brandParam);
		page.setItemList(list);
		page.setTotalRecord(count);
		page.setPageNo(brandParam.getPageNo());
		page.setPageSize(brandParam.getPageSize());
		return page;
	}

	@Override
	public GoodsBrand queryGoodsBrand(Integer brandId) {
		return goodsBrandMapper.selectByPrimaryKey(brandId);
	}

	@Override
	public int updateGoodsBrand(GoodsBrandInfo info) {
		GoodsBrand brand = new GoodsBrand();
		brand.setEnglishName(info.getEnglishName());
		brand.setName(info.getName());
		brand.setId(info.getId());
		return goodsBrandMapper.updateByPrimaryKeySelective(brand);
	}

	@Override
	public int saveGoodsBrand(GoodsBrandInfo info, String userName) {
		GoodsBrand brand = new GoodsBrand();
		brand.setCreateTime(new Date());
		brand.setCreator(userName);
		brand.setEnglishName(info.getEnglishName());
		brand.setName(info.getName());
		brand.setId(info.getId());
		return goodsBrandMapper.insertSelective(brand);
	}

	@Override
	public Integer deleteGoodsBrand(Integer brandId) {
		return goodsBrandMapper.deleteByPrimaryKey(brandId);
	}
}
